const conn=require('../utils/sqlMethods.js');

module.exports={
    getAllCateList(n1,n2,callback){
        let sql=`select posts.*,categories.name,users.nickname from posts 
                  join categories on posts.category_id=categories.id
                  join users on posts.user_id=users.id
                  ORDER BY id desc
                  limit ${n1},${n2}`
       conn.query(sql,(err,result)=>{
           if(err)return callback(err);
           sql=`select count(*) as total from posts`
           conn.query(sql,(err1,result1)=>{
               if(err1) return callback(err1)
               callback(null,{data:result,cnt:result1[0].total});
           })
           
       })
    }
}